package com.ruoyi.mobile.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ruoyi.mobile.domain.User;
import com.ruoyi.mobile.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mobile.domain.CheckinRecord;
import com.ruoyi.mobile.service.ICheckinRecordService;

/**
 * 打卡记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-05
 */
@Service
public class CheckinRecordServiceImpl implements ICheckinRecordService 
{
    @Autowired
    private CheckinRecordMapper checkinRecordMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private LessonMapper lessonMapper;


    /**
     * 查询打卡记录列表
     * 
     * @param checkinRecord 打卡记录
     * @return 打卡记录
     */
    @Override
    public List<CheckinRecord> selectCheckinRecordList(CheckinRecord checkinRecord)
    {
        List<CheckinRecord> list = checkinRecordMapper.selectCheckinRecordList(checkinRecord);
        List<Integer> userIdList = new ArrayList<Integer>();
        for(CheckinRecord checkinRecord1 : list) {
            Integer userId = checkinRecord1.getUserId();
            if (!userIdList.contains(userId)) {
                userIdList.add(userId);
            }
        }
        //获取user信息
        if (!userIdList.isEmpty()) {
            Map<Integer, User> userList = userMapper.getUsersByIds(userIdList);
            if (!userList.isEmpty()) {
                for(CheckinRecord checkinRecord1 : list) {
                    Integer userId = checkinRecord1.getUserId();
                    User user = userList.get(userId);
                    checkinRecord1.setNickname(user.getNickname());
                    checkinRecord1.setPhone(user.getPhone());
                }
            }
        }

        return list;
    }
}
